home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / network / admin / xinetd.2 / xinetd / xinetd.2.1.7-linux.4 / libs / src / str / strprint.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-25  |  3.5 KB  |  216 lines

  1. /*
  2.  * (c) Copyright 1992, 1993 by Panagiotis Tsirigotis
  3.  * All rights reserved.  The file named COPYRIGHT specifies the terms 
  4.  * and conditions for redistribution.
  5.  */
  6.  
  7. static char RCSid[] = "$Id: strprint.c,v 3.1 1993/06/13 02:50:11 panos Exp $" ;
  8.  
  9. #ifndef NO_SIO
  10. #include "sio.h"
  11. #endif
  12.  
  13. #include "str.h"
  14.  
  15. #define INT_NULL                        ((int *)0)
  16.  
  17. /*
  18.  * The strx_* functions will never overwrite the buffer
  19.  * The str_* functions may overwrite the buffer
  20.  */
  21.  
  22. /*
  23.  * Group 1: the strx_* functions
  24.  */
  25.  
  26. /*
  27.  * This is the general purpose conversion function. It is invoked
  28.  * by all the other str[x]_* functions
  29.  */
  30. void strx_printv( ccp, buf, len, format, ap )
  31.     int *ccp ;
  32.     char *buf ;
  33.     int len ;
  34.     char *format ;
  35.     va_list ap ;
  36. {
  37. #ifndef NO_SIO
  38.     __sio_od_t od ;
  39.     int cc ;
  40.  
  41.    /*
  42.     * First initialize the descriptor
  43.      * Notice that if no length is given, we initialize buf_end to the
  44.      * highest possible address.
  45.     */
  46.    od.buf = buf ;                                        /* NOT NEEDED        */
  47.    od.buf_end = len ? &buf[ len ] : (char *) ~0 ;    /* NEEDED                */
  48.    od.buffer_size = 0 ;                                  /* NOT NEEDED        */
  49.    od.start = buf ;                                      /* NOT NEEDED        */
  50.    od.nextb = buf ;                                      /* NEEDED            */
  51.    od.buftype = 0 ;                                      /* NOT NEEDED        */
  52.  
  53.    /*
  54.     * Do the conversion
  55.     */
  56.    cc = __sio_converter( &od, -1, format, ap ) ;
  57.     if ( len == 0 || od.nextb < od.buf_end )
  58.         *(od.nextb) = '\0' ;
  59.    if ( ccp )
  60.       *ccp = cc ;
  61. #endif    /* ! NO_SIO */
  62. }
  63.  
  64.  
  65. void strx_print( ccp, buf, len, format, va_alist )
  66.     int *ccp ;
  67.     char *buf ;
  68.     int len ;
  69.     char *format ;
  70.     va_dcl
  71. {
  72.     va_list ap ;
  73.  
  74.     va_start( ap ) ;
  75.     strx_printv( ccp, buf, len, format, ap ) ;
  76.     va_end( ap ) ;
  77. }
  78.  
  79.  
  80. char *strx_sprint( buf, len, format, va_alist )
  81.     char *buf ;
  82.     int len ;
  83.     char *format ;
  84.     va_dcl
  85. {
  86.     va_list ap ;
  87.  
  88.     va_start( ap ) ;
  89.     strx_printv( INT_NULL, buf, len, format, ap ) ;
  90.     va_end( ap ) ;
  91.     return( buf ) ;
  92. }
  93.  
  94.  
  95. char *strx_sprintv( buf, len, format, ap )
  96.     char *buf ;
  97.     int len ;
  98.     char *format ;
  99.     va_list ap ;
  100. {
  101.     strx_printv( INT_NULL, buf, len, format, ap ) ;
  102.     return( buf ) ;
  103. }
  104.  
  105.  
  106. int strx_nprint( buf, len, format, va_alist )
  107.     char *buf ;
  108.     int len ;
  109.     char *format ;
  110.     va_dcl
  111. {
  112.     int cc ;
  113.     va_list ap ;
  114.  
  115.     va_start( ap ) ;
  116.     strx_printv( &cc, buf, len, format, ap ) ;
  117.     va_end( ap ) ;
  118.     return( cc ) ;
  119. }
  120.  
  121.  
  122. int strx_nprintv( buf, len, format, ap )
  123.     char *buf ;
  124.     int len ;
  125.     char *format ;
  126.     va_list ap ;
  127. {
  128.     int cc ;
  129.  
  130.     strx_printv( &cc, buf, len, format, ap ) ;
  131.     return( cc ) ;
  132. }
  133.  
  134.  
  135.  
  136. /*
  137.  * Group 2: the str_* functions
  138.  */
  139.  
  140. void str_print( ccp, buf, format, va_alist )
  141.     int *ccp ;
  142.     char *buf ;
  143.     char *format ;
  144.     va_dcl
  145. {
  146.     va_list ap ;
  147.  
  148.     va_start( ap ) ;
  149.     strx_printv( ccp, buf, 0, format, ap ) ;
  150.     va_end( ap ) ;
  151. }
  152.  
  153.  
  154. void str_printv( ccp, buf, format, ap )
  155.     int *ccp ;
  156.     char *buf ;
  157.     char *format ;
  158.     va_list ap ;
  159. {
  160.     strx_printv( ccp, buf, 0, format, ap ) ;
  161. }
  162.  
  163.  
  164. char *str_sprint( buf, format, va_alist )
  165.     char *buf ;
  166.     char *format ;
  167.     va_dcl
  168. {
  169.     va_list ap ;
  170.  
  171.     va_start( ap ) ;
  172.     strx_printv( INT_NULL, buf, 0, format, ap ) ;
  173.     va_end( ap ) ;
  174.     return( buf ) ;
  175. }
  176.  
  177.  
  178. char *str_sprintv( buf, format, ap )
  179.     char *buf ;
  180.     char *format ;
  181.     va_list ap ;
  182. {
  183.     strx_printv( INT_NULL, buf, 0, format, ap ) ;
  184.     return( buf ) ;
  185. }
  186.  
  187.  
  188. int str_nprint( buf, format, va_alist )
  189.     char *buf ;
  190.     char *format ;
  191.     va_dcl
  192. {
  193.     int cc ;
  194.     va_list ap ;
  195.  
  196.     va_start( ap ) ;
  197.     strx_printv( &cc, buf, 0, format, ap ) ;
  198.     va_end( ap ) ;
  199.     return( cc ) ;
  200. }
  201.  
  202.  
  203.  
  204. int str_nprintv( buf, format, ap )
  205.     char *buf ;
  206.     char *format ;
  207.     va_list ap ;
  208. {
  209.     int cc ;
  210.  
  211.     strx_printv( &cc, buf, 0, format, ap ) ;
  212.     return( cc ) ;
  213. }
  214.  
  215.  
  216.